<!DOCTYPE html PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML>
<HEAD>
<TITLE>Grammar for ArmBob 4.0</TITLE>
<LINK REL=STYLESHEET HREF="style.css" TYPE="text/css">
</HEAD>
<BODY style="margin-left: 6em;">
<H2>Grammar for ArmBob 4.0</H2>
<P>
ArmBob <A HREF="#Syntax">Syntax</A> follows that of C, with some
extensions and some omissions.
Every statement returns a value, including 
assignment statements.
<P>
<H4>Comments</H4>
Armbob has two kinds of comment: single- and multi-line. 
They have the same syntax as comments in C++.
<UL>
 <LI>Single-line comments are introduced by <CODE>//</CODE>
    and are terminated by the end of the line or file.
 <LI>Multi-line comments start with <CODE>/*</CODE>
     and end with the next <CODE>*/</CODE>. They are
     not nestable.
</UL>
<H4>Names</H4>
Blank spaces, tab characters and newlines are ignored in 
Armbob, except in so far as they mark the end of a name. 
Names must begin with a letter of the alphabet, and 
subsequently must consist of letters of the alphabet,
digits, or the characters 
<CODE>&#95; &#64; &#36;</CODE> .
<P>
It may be useful, but it is not mandatory, to use 
these extra characters as prefixes or suffixes on names, 
to indicate the type of object they denote, in the 
following way:
<UL>
<LI><CODE>&#64;</CODE> for addresses of buffers in memory
<LI><CODE>&#36;</CODE> for strings
</UL>
This mnemonic convention fits the names for the storage 
functions needed for low-level access. Thus, if 
<CODE>s</CODE> is a string, <CODE>&#64;(s)</CODE>
denotes the integer address at which the contents 
of <CODE>s</CODE> are held. If <CODE>a</CODE> is
an address <CODE>&#36;(a)</CODE> denotes the string
at <CODE>a</CODE>, terminated by a control character,
<CODE>word(a)</CODE> denotes the word and
<CODE>byte(a)</CODE> the byte stored at
<CODE>a</CODE>.
<P>
Names may be up to 50 characters long. 
Program lines may be up to 200 characters long.
<HR>
<H4><A NAME="Syntax"> Syntax</A></H4>

<DL>
<DT><EM>Program</EM> ::= 
<DD>[ Defs ] Main_def [ Defs ]

<DT><EM>Defs</EM> ::= 
<DD>Def [ Defs ]

<DT><EM>Def</EM> ::= 
<DD>Class_Def | Fun_def

<DT><EM>Class_def</EM> ::= 
<DD><CODE>class</CODE> CName 
    [ <CODE>:</CODE> CName ]
    <CODE>{</CODE> Class_body <CODE>}</CODE>

<DT><EM>Fun_def</EM> ::= 
<DD>[ CName <CODE>::</CODE> ]
    FName <CODE>(</CODE> [ FArgs ] 
    <CODE>) {</CODE> Fun_body <CODE>}</CODE>

<DT><EM>Main_def</EM> ::= 
<DD><CODE>main() {</CODE> Fun_body <CODE>}</CODE>

<DT><EM>Class_body</EM> ::= 
<DD>Member <CODE>;</CODE> [ Class_body ]

<DT><EM>Member</EM> ::= 
<DD>[<CODE>static</CODE>] Data | [<CODE>static</CODE>]
            FName <CODE>(</CODE> [ FArgs ] <CODE>)</CODE>

<DT><EM>Data</EM> ::= 
<DD>Variable [ <CODE>,</CODE> Data ]

<DT><EM>FArgs</EM> ::= 
<DD>Variable [ <CODE>,</CODE> FArgs ]

<DT><EM>Fun_body</EM> ::= 
<DD>[ <CODE>local</CODE> Args <CODE>;</CODE> ]
                      Statements

<DT><EM>Statements</EM> ::= 
<DD>Statement Statements

<DT><EM>Statement</EM> ::= 
<DD>[ Single ] <CODE>;</CODE> |
             <CODE>{</CODE> Statements <CODE>}</CODE>
             | Control

<DT><EM>Control</EM> ::= 
<DD><CODE>if (</CODE> Expr <CODE>)</CODE>
                   Statement [ <CODE>else</CODE> Statement ]

<DD>| <CODE>while (</CODE> Expr <CODE>)</CODE> Statement

<DD>| <CODE>do</CODE> Statement <CODE> while (</CODE>
 Expr <CODE>)</CODE>

<DD>| <CODE>repeat</CODE> Statement <CODE>until (</CODE>
 Expr <CODE>)</CODE>

<DD>| <CODE>do</CODE> Statement <CODE> until (</CODE>
 Expr <CODE>)</CODE>

<DD>| <CODE>repeat</CODE> Statement <CODE>while (</CODE>
 Expr <CODE>)</CODE>

<DD>| <CODE>for (</CODE> Expr <CODE>;</CODE>
  Expr <CODE>;</CODE> Expr <CODE>)</CODE>
  Statement

<DD>| <CODE>switch (</CODE> Expr <CODE>) {</CODE>
  Alternatives [ <CODE>default :</CODE>
  Statements ] <CODE>}</CODE>

<DD>| <CODE>in</CODE> Expr <CODE>put {</CODE>
  Items <CODE>}</CODE>
         
<DT><EM>Single</EM> ::= 
<DD><CODE>break</CODE> |
                    <CODE>continue</CODE> |
                    <CODE>return</CODE> Expr | Expr

<DT><EM>Items</EM> ::= 
<DD>Expr <CODE>;</CODE> Items

<DT><EM>Alternatives</EM> ::= 
<DD><CODE>case</CODE> Expr <CODE>:</CODE>
            Statements [ Alternatives ]

<DT><EM>Expr</EM> ::= 
<DD>Expr <CODE>,</CODE> Expr

<DD>| Lvalue Assign Expr

<DD>| Expr <CODE>?</CODE> Expr <CODE>:</CODE> Expr

<DD>| Expr Binop Expr

<DD>| Unop Expr

<DD>| <CODE>++</CODE> Lvalue

<DD>| Lvalue <CODE>++</CODE>

<DD>| <CODE>--</CODE> Lvalue

<DD>| Lvalue <CODE>--</CODE>

<DD>| <CODE>new</CODE> Cname <CODE>(</CODE>
  [ Expr ] <CODE>)</CODE>

<DD>| Expr <CODE>(</CODE> [ Expr ] <CODE>)</CODE>

<DD>| Expr <CODE>-&gt;</CODE> Fname <CODE>(</CODE>
  [ Expr ] <CODE>)</CODE>

<DD>| Expr <CODE>[</CODE> Expr <CODE>]</CODE>

<DD>| <CODE>vector {</CODE> Items <CODE>}</CODE>

<DD>| <CODE>enum {</CODE> Data <CODE>}</CODE>

<DD>| <CODE>(</CODE> Expr <CODE>)</CODE>

<DD>| Variable

<DD>| Number

<DD>| <CODE>&quot;</CODE>String<CODE>&quot;</CODE>

<DD>| <CODE>' </CODE>Character<CODE>'</CODE>

<DD>| <CODE>nil</CODE>

<DT><EM>Assign</EM> ::= 
<DD><CODE> = </CODE> |
                    <CODE> += </CODE> |
                    <CODE> -= </CODE> |
                    <CODE> *= </CODE> |
                    <CODE> /= </CODE> |
                    <CODE> %= </CODE> |
                    <CODE> &amp;= </CODE> |
                    <CODE> |= </CODE> |
                    <CODE> ^= </CODE> |
                    <CODE> &lt;&lt;= </CODE> |
                    <CODE> &gt;&gt;= </CODE>

<DT><EM>Binop</EM> ::= 
<DD><CODE>|| </CODE> |
                   <CODE>| </CODE> | 
                   <CODE> &amp;&amp; </CODE> |
                   <CODE> &amp; </CODE> |
                   <CODE> ^ </CODE> |
                   <CODE> == </CODE> |
                   <CODE> != </CODE> |
                   <CODE> &lt; </CODE> |
                   <CODE> &lt;= </CODE> |
                   <CODE> &gt; </CODE> |
                   <CODE> &gt;=</CODE> | 
                   <CODE> &gt;&gt;</CODE> |
                   <CODE> &lt;&lt;</CODE> | 
                   <CODE> + </CODE> |
                   <CODE> - </CODE> |
                   <CODE> * </CODE> |
                   <CODE> % </CODE> |
                   <CODE> / </CODE>

<DT><EM>Unop</EM> ::= 
<DD><CODE> - </CODE> 
                | <CODE> ! </CODE>
                | <CODE> ~ </CODE>        

<DT><EM>Lvalue</EM> ::= 
<DD>Variable 
                  | Expr <CODE>[</CODE> Expr <CODE>]</CODE>

<DT><EM>Number</EM> ::= 
<DD>Decimal[<CODE>.</CODE>decimal]
                  | <CODE>&amp;</CODE>Hexnumber

<DT><EM>Decimal</EM> ::= 
<DD>Digit Decimal

<DT><EM>Hexnumber</EM> ::= 
<DD>Hexdigit Hexnumber

<DT><EM>Digit</EM> ::= 
<DD><CODE>0</CODE>
                 | <CODE>1</CODE>
                 | <CODE>2</CODE>
                 | <CODE>3</CODE>
                 | <CODE>4</CODE>
                 | <CODE>5</CODE>
                 | <CODE>6</CODE>
                 | <CODE>7</CODE>
                 | <CODE>8</CODE>
                 | <CODE>9</CODE>

<DT><EM>Hexdigit></EM> ::= 
<DD>Digit
                    | <CODE>a</CODE>
                    | <CODE>b</CODE>
                    | <CODE>c</CODE>
                    | <CODE>d</CODE>
                    | <CODE>e</CODE>
                    | <CODE>f</CODE>

<DT><EM>Character</EM> ::= 
<DD>Char | <CODE>&quot;</CODE>

<DT><EM>String</EM> ::= 
<DD>Char String

<DT><EM>Char</EM> ::= 
<DD><CODE>\n</CODE>
                | <CODE>\t</CODE>
                | <CODE>\\</CODE> 
     | Any ASCII character except &quot;, \ or control code

<DT><EM>Cname</EM> ::= 
<DD>Identifier

<DT><EM>Fname</EM> ::= 
<DD>Identifier

<DT><EM>Variable</EM> ::= 
<DD>Identifier

<DT><EM>Identifier</EM> ::= 
<DD>Alpha | Digit

<DT><EM>Alpha</EM> ::= 
<DD>[<CODE>A-Z</CODE>]
                 | [<CODE>a-z</CODE>]
                 | <CODE>&#95;</CODE>
                 | <CODE>&#64;</CODE>
                 | <CODE>&#36;</CODE>
                
</DL>
<HR>
<A HREF="index.html">Back to the index</A>
</BODY>
</HTML>

